package cn.ubeta.b2c.user;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import cn.ubeta.b2c.R;
import cn.ubeta.b2c.common.AnalyseActivity;
import cn.ubeta.b2c.user.coupon.CouponFragment;
import com.ogaclejapan.smarttablayout.SmartTabLayout;

/**
 * Created by denny on 16/9/5.
 */

public class CouponActivity extends AnalyseActivity {

    private PagerAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState, R.layout.activity_coupon);

        final ViewPager pager = (ViewPager) findViewById(R.id.vp_page);
        mAdapter = new PagerAdapter(getSupportFragmentManager());
        pager.setAdapter(mAdapter);

        SmartTabLayout mTabLayout = (SmartTabLayout) findViewById(R.id.tab_bar);
        mTabLayout.setViewPager(pager);
    }

    class PagerAdapter extends FragmentPagerAdapter {

        private final String[] TITLES = {"未使用", "已过期", "已使用"};

        public PagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return TITLES[position];
        }

        @Override
        public int getCount() {
            return TITLES.length;
        }

        @Override
        public Fragment getItem(int position) {
            return CouponFragment.newInstance(getTypeFromPosition(position));
        }

        /**
         * 从位置获取优惠券类型
         * @param pos
         * @return
         */
        private int getTypeFromPosition(int pos) {
            return pos; // TODO 从位置获取优惠券类型
        }
    }
}
